const state = {
  sidebarCollapsed: false
}

const mutations = {
  TOGGLE_SIDEBAR: (state) => {
    state.sidebarCollapsed = !state.sidebarCollapsed
  },
  SET_SIDEBAR_STATE: (state, collapsed) => {
    state.sidebarCollapsed = collapsed
  }
}

const actions = {
  toggleSidebar({ commit }) {
    commit('TOGGLE_SIDEBAR')
  },
  setSidebarState({ commit }, collapsed) {
    commit('SET_SIDEBAR_STATE', collapsed)
  },
  // 初始化应用
  async initializeApp({ dispatch, rootState }) {
    // 检查是否存在 token
    if (rootState.auth.token) {
      // 如果有 token，尝试获取用户信息
      await dispatch('auth/getProfile', null, { root: true });
    }
    // 可以在这里添加其他初始化逻辑，例如加载用户设置等
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}